import com.security.User
import com.security.Role
import com.security.UserRole
import assignmentonepenguins.Customer

class BootStrap {

    def init = { servletContext ->
        def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true)
        def userRole = new Role(authority: 'ROLE_USER').save(flush: true)

        def testUser = new User(username: 'admin', enabled: true, password: 'password')
        testUser.save(flush: true)

        UserRole.create testUser, adminRole, true
        Customer customer1 = new Customer()
        customer1.setEmail("admin01@gmail.com")
        customer1.setUsername("admin")
        customer1.setPassword("password")
        customer1.save(flush: true)

//        def testUser1 = new User(username: 'vikas', enabled: true, password: 'password')
//        testUser1.save(flush: true)
//
//        UserRole.create testUser1, userRole, true

        assert User.count() == 1
        assert Role.count() == 2
        assert UserRole.count() == 1
    }
    def destroy = {
    }
}
